import { ref } from "vue";
import PageDialog from "@/components/page-dialog";
type newCb = () => void;
type editCb = (row?: any) => void;
export function useEditAndNewUser(newCb?: newCb, editCb?: editCb) {
  const defaultInfo = ref({});
  /* 新建 */
  const dialogRef = ref<InstanceType<typeof PageDialog>>();
  // 监听新建按钮的点击
  const addNewUser = () => {
    if (dialogRef.value) {
      // 重置表单
      defaultInfo.value = {};
      newCb && newCb();
      dialogRef.value.dialogVisible = true;
    }
  };
  /* 编辑 */
  const editUser = (userInfo: any) => {
    if (dialogRef.value) {
      // 数据回显
      defaultInfo.value = userInfo;
      editCb && editCb(userInfo);
      dialogRef.value.dialogVisible = true;
    }
  };
  return [defaultInfo, dialogRef, addNewUser, editUser];
}
